package com.jketing.spring.mvc.converter.ams;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.jketing.entity.ams.base.Employee;
import com.jketing.entity.ams.base.Organ;

/**
 * EmployeeConverter 自定义类型转化器
 * 
 * @author  李荣华
 * @version v1.0
 * @date    2018-01-02
 * @since   Spring-mvc 4.3.8
 */
@Component
public class EmployeeConverter implements Converter<String, Employee> {

	@Override
	public Employee convert(String source) {
		if(source != null){
			String [] vals = source.split("-");
			//GG-gg@atguigu.com-0-105
			if(vals != null && vals.length == 4){
				String lastName = vals[0];
				String email = vals[1];
				Integer gender = Integer.parseInt(vals[2]);
				Organ department = new Organ();
				department.setId(vals[3]);
				
				Employee employee = new Employee();
				System.out.println(source + "--convert--" + employee);
				return employee;
			}
		}
		return null;
	}

}
